from django.utils.deprecation import MiddlewareMixin
from django.http import HttpResponse


class BlockedIPSMiddleware(MiddlewareMixin):
    EXCLUDE_IPS = ["192.168.1.42", "192.168.1.205", "192.168.1.46"]

    def process_view(self, request, view_func, *view_args, **view_kwargs):
        user_ip = request.META['REMOTE_ADDR']
        if user_ip.startswith("192.168.1.1"):
            return HttpResponse("该IP不可以访问")
        else:
            return None





